<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

/**
 * 初始化WordPress兼容的Session中间件
 */
class InitializeWordPressSession
{
    /**
     * Handle an incoming request.
     */
    public function handle(Request $request, Closure $next): Response
    {
        // 确保session已初始化
        if (!$request->hasSession()) {
            $session = app('session.store');
            $session->start();
            $request->setLaravelSession($session);
        }

        return $next($request);
    }
}
